# lsup_rdf package.
# All "modules" are inside the monolythic lsup_rdf extension because they have
# cross-linked symbols, so they need a bit of work to be exposed at the main
# level.

import importlib.util
import sys

import _lsup_rdf
from _lsup_rdf import env_init


pkg_path = _lsup_rdf.__file__


def _load_module(mod_name, path):
    """
    Replacement of deprecated imp.load_dynamic(). See
    https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
    """
    spec = importlib.util.spec_from_file_location(mod_name, path)
    module = importlib.util.module_from_spec(spec)
    sys.modules['lsup_rdf.' + mod_name] = module
    spec.loader.exec_module(module)

    return module


for mod_name in ('term', 'triple', 'namespace', 'graph'):
    locals()[mod_name] = _load_module(mod_name, pkg_path)
